import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
import _createClass from "@babel/runtime/helpers/esm/createClass";
import _inherits from "@babel/runtime/helpers/esm/inherits";
import _createSuper from "@babel/runtime/helpers/esm/createSuper";

/**
 * DataTable
 * @date 2019/9/29
 */
import React, { Component } from 'react';
import { Popconfirm, Table } from 'antd';
import intl from "../../../utils/intl";
import { tableScrollWidth } from "../../../utils/utils";
import { TagRender, dateTimeRender } from "../../../utils/renderer";

var DataTable = /*#__PURE__*/function (_Component) {
  _inherits(DataTable, _Component);

  var _super = _createSuper(DataTable);

  function DataTable() {
    _classCallCheck(this, DataTable);

    return _super.apply(this, arguments);
  }

  _createClass(DataTable, [{
    key: "getColumns",
    value: function getColumns() {
      var _this = this;

      return [{
        title: intl.get('cpaas.common.component.excelExport.hd.m.hd.taskCode').d('任务编号'),
        width: 240,
        dataIndex: 'taskCode'
      }, {
        title: intl.get('cpaas.common.component.excelExport.hd.m.hd.taskName').d('任务名称'),
        dataIndex: 'taskName'
      }, {
        title: intl.get('cpaas.common.component.excelExport.hd.m.hd.serviceName').d('所属服务'),
        dataIndex: 'serviceName',
        width: 200
      }, {
        title: intl.get('cpaas.common.component.excelExport.hd.m.hd.state').d('任务状态'),
        width: 120,
        dataIndex: 'state',
        render: function render(val) {
          var statusLists = [{
            status: 'DONE',
            color: 'green',
            text: intl.get('cpaas.common.component.excelExport.hd.m.hd.state.done').d('已结束')
          }, {
            status: 'DOING',
            color: '',
            text: intl.get('cpaas.common.component.excelExport.hd.m.hd.state.doing').d('正在进行')
          }, {
            status: 'CANCELLED',
            color: 'red',
            text: intl.get('cpaas.common.component.excelExport.hd.m.hd.state.cancelled').d('已取消')
          }];
          return TagRender(val, statusLists);
        }
      }, {
        title: intl.get('cpaas.common.component.excelExport.hd.m.hd.endDateTime').d('任务结束时间'),
        dataIndex: 'endDateTime',
        width: 200,
        render: dateTimeRender
      }, {
        title: intl.get('cpaas.common.component.excelExport.hd.m.hd.errorInfo').d('异常信息'),
        dataIndex: 'errorInfo',
        render: function render(errorInfo) {
          return errorInfo ? /*#__PURE__*/React.createElement("a", {
            onClick: function onClick() {
              var onShowErrorInfo = _this.props.onShowErrorInfo;
              onShowErrorInfo(errorInfo);
            }
          }, errorInfo) : null;
        }
      }, {
        title: intl.get('cpaas.common.button.action').d('操作'),
        width: 60,
        fixed: 'right',
        render: function render(text, record) {
          var _this$props = _this.props,
              onRecordDownload = _this$props.onRecordDownload,
              onRecordCancel = _this$props.onRecordCancel;
          return /*#__PURE__*/React.createElement("span", {
            className: "action-link"
          }, record.state === 'DONE' && /*#__PURE__*/React.createElement("a", {
            onClick: function onClick() {
              onRecordDownload(record);
            }
          }, intl.get('cpaas.common.button.download').d('下载')), record.state === 'DOING' && /*#__PURE__*/React.createElement(Popconfirm, {
            title: intl.get('cpaas.common.message.confirm.cancel').d('是否取消导出？'),
            onConfirm: function onConfirm() {
              onRecordCancel(record);
            }
          }, /*#__PURE__*/React.createElement("a", null, intl.get('cpaas.common.button.cancel').d('取消'))));
        }
      }];
    }
  }, {
    key: "render",
    value: function render() {
      var _this$props2 = this.props,
          _this$props2$dataSour = _this$props2.dataSource,
          dataSource = _this$props2$dataSour === void 0 ? [] : _this$props2$dataSour,
          _this$props2$paginati = _this$props2.pagination,
          pagination = _this$props2$paginati === void 0 ? {} : _this$props2$paginati,
          onChange = _this$props2.onChange,
          _this$props2$loading = _this$props2.loading,
          loading = _this$props2$loading === void 0 ? false : _this$props2$loading;
      var columns = this.getColumns();
      return /*#__PURE__*/React.createElement(Table, {
        bordered: true,
        loading: loading,
        columns: columns,
        scroll: {
          x: tableScrollWidth(columns)
        },
        dataSource: dataSource,
        pagination: pagination,
        onChange: onChange
      });
    }
  }]);

  return DataTable;
}(Component);

export { DataTable as default };